/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.ArrayList;
import model.Thanhtoan;
import model.Thanhvien;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import util.HibernateUtil;

/**
 *
 * @author HoangLiem
 */
public class ThanhToanDAO {
    public static ArrayList<Thanhtoan> getAllPayments(){
        ArrayList<Thanhtoan> list =new ArrayList<Thanhtoan>();
        try{
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction trans = session.getTransaction();
            trans.begin();
            String hql="from Thanhtoan";
            Query query = session.createQuery(hql);
            list = (ArrayList<Thanhtoan>)query.list();
            trans.commit();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return list;
    }
    public static ArrayList<Thanhtoan> getAllPaymentsByUser(Thanhvien thanhvien){
        ArrayList<Thanhtoan> list =new ArrayList<Thanhtoan>();
        try{
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
           Transaction trans = session.getTransaction();
            trans.begin();
            String hql="from Thanhtoan tt where tt.thanhvien =:thanhvien";
            Query query = session.createQuery(hql);
            query.setEntity("thanhvien", thanhvien);
            list = (ArrayList<Thanhtoan>)query.list();
            trans.commit();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return list;
    }
}
